class Solution(object):
    def eraseOverlapIntervals(self, intervals):
        """
        :type intervals: List[List[int]]
        :rtype: int
        """
        intervals =  sorted(intervals, key=lambda x:x[1])

        end = intervals[0][1]
        ans = 1
        for i in range(1, len(intervals)):
            if intervals[i][0] >= end:
                ans += 1
                end = intervals[i][1]
        return len(intervals) - ans
